-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.js
35 lines (29 loc) · 965 Bytes
/
code.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Define the global variables: img, offset, and easing.
// Set offset to 0 and easing to 0.05 for moving the
// transparent image with the cursor position.
let img;
let offset = 0;
let easing = 0.05;
function preload() {
// Load the bottom image from the canvas's assets directory.
img = loadImage('assets/moonwalk.jpg');
}
function setup() {
describe(
"An astronaut on a planet as the background with a slightly transparent version of this image on top that moves with the horizontal direction of the user's mouse."
);
createCanvas(720, 400);
}
function draw() {
// Display the bottom image at full opacity.
tint(255, 255);
image(img, 0, 0);
// Define dx as the rate at which the top image
// moves with the cursor. The offset variable
// delays the movement of the image.
let dx = mouseX - img.width / 2 - offset;
offset += dx * easing;
// Display the top image at half opacity.
tint(255, 127);
image(img, offset, 0);
}